package com.wude.guild.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;

import com.wude.bean.ShareInfo;
import com.wude.guild.R;
import com.wude.tools.Shares;

import org.xutils.x;

/**
 * Created by Administrator on 2017/11/23 0023.
 */

public class SharedDialog extends Dialog implements View.OnClickListener {
    private ShareInfo shareInfo;
    private int name;

    private RelativeLayout qq, weixin, pyq, kongjian;

    public SharedDialog(@NonNull Context context, ShareInfo shareInfo, int name) {
        super(context);
        this.shareInfo = shareInfo;
        this.name = name;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);// 去标题栏
        setContentView(R.layout.activity_share);

        // 宽度充满整个手机屏
        Window window = this.getWindow();
        window.setBackgroundDrawableResource(R.color.transparency);
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.FILL_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        //在手机屏幕下方
        window.setAttributes(lp);
        window.setGravity(Gravity.BOTTOM);

        initView();
    }

    private void initView() {
        qq = findViewById(R.id.qq);
        weixin = findViewById(R.id.weixin);
        pyq = findViewById(R.id.pyq);
        kongjian = findViewById(R.id.kongjian);

        kongjian.setOnClickListener(this);
        pyq.setOnClickListener(this);
        weixin.setOnClickListener(this);
        qq.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        Shares.TYPE = name;
        switch (view.getId()) {
            case R.id.qq:                   //分享到QQ
                Shares.QQ(x.app(), shareInfo);
                break;
            case R.id.weixin:               //分享到微信
                Shares.Wechat(x.app(), shareInfo);
                break;
            case R.id.pyq:                  //分享到微信朋友圈
                Shares.WechatMoments(x.app(), shareInfo);
                break;
            case R.id.kongjian:             //分享到QQ空间
                Shares.QZone(x.app(), shareInfo);
                break;
        }
        dismiss();
    }
}
